package com.one.group.user.exception;

import com.one.group.enums.ErrorCode;
import com.one.group.exception.BusinessException;
import com.one.group.result.Result;
import com.one.group.utils.ResultUtil;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * {@code @Create:}  2025-09-08  10 : 36
 * {@code @Author:} Cherry
 * {@code @ToUser:} 凡是发生,皆有利于我。
 * ------------------------------------
 * {@code @note:}
 */

@SuppressWarnings({"all"})
@RestControllerAdvice
@Hidden
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public Result BusinessException(BusinessException e) {
        log.debug("自定义异常:{}", e.getMessage());
        return ResultUtil.error(e.getCode(), e.getMessage());
    }

    //未知异常
    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        log.error("未知异常:{}", e.getMessage());
        return ResultUtil.error(ErrorCode.SYSTEM_ERROR, "系统繁忙，请稍后再来!");
    }
}
